package com.js.myapp.system.activity;

// Created by JS on 2021/7/15.

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.js.baseview.refresh.SwipeRefreshLayout;
import com.js.baseview.refresh.ext.GoLoadingLayout;
import com.js.baseview.refresh.ext.moveopen.MoveOpenAndRefreshLayout;
import com.js.myapp.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SwipeRefreshLayoutActivity extends BaseActivity {

    @BindView(R.id.freshLayout)
    MoveOpenAndRefreshLayout freshLayout;
    @BindView(R.id.goLayout)
    GoLoadingLayout goLayout;

    public static void start(Context context) {
        Intent intent = new Intent(context, SwipeRefreshLayoutActivity.class);
        context.startActivity(intent);
    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_swipe_refresh_layout;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        freshLayout.setOnRefreshListener(new MoveOpenAndRefreshLayout.OpenRefreshListener() {
            @Override
            public void openActivity() {
                goLayout.stopAnimation();
            }

            @Override
            public void onRefresh() {
                freshLayout.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        goLayout.repeatAnimation();
                        freshLayout.stopRefresh();
                    }
                }, 3000);
            }
        });
        goLayout.repeatAnimation();
    }
}
